
import { defineStore } from 'pinia'
import { $get } from '@/lib/plugin/Aegis'

type RootState = {
  typeId: string;
  typeList: {
    id: number;
    name: string;
    created_at: string;
    updated_at: string
  } | null;
};

export const typeStore = defineStore('type', {
  state: () => {
    return {
      typeId: '',
      typeList: null
    } as RootState
  },
  getters: {},
  actions: {
    changeTypeId (res:string):void {
      this.typeId = res
    },
    changeTypeList (res:any):void {
      this.typeList = res
    },
    async getTypeList (params:any) {
      params ||= {
        nowPage: 1,
        pageSize: 10
      }
      try {
        this.typeList = (await $get('type/list', params)).rows
      } catch (error) {
        console.log(error)
      }
    }
  }
})
